package com.zzyl.controller;


import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.service.impl.NursingProjectServiceImpl;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing_project")
@Api(value = "护理项目管理")
public class NursingProjectController {


    @Autowired
    private NursingProjectService nursingProjectService;

    /**
     * 分页查询
     * @param name
     * @param pageNum
     * @param pageSize
     * @param status
     * @return ResponseResult<PageResponse<NursingProjectVo>>
     */
    @GetMapping
    @ApiOperation(value = "分页查询")
    public ResponseResult<PageResponse<NursingProjectVo>> queryPage(String name,
                                                                    @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                                    @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                                    Integer status) {
        PageResponse<NursingProjectVo> queryPages = nursingProjectService.queryPage(name, pageNum, pageSize, status);
        return ResponseResult.success(queryPages);
    }

    /**
     *  添加护理项目
     * @param nursingProjectDto
     * @return ResponseResult
     */
    @PostMapping
    @ApiOperation(value = "添加护理项目")
    public ResponseResult add(@RequestBody NursingProjectDto nursingProjectDto) {
        nursingProjectService.add(nursingProjectDto);
        return ResponseResult.success();
    }

    /**
     * 根据id查询护理项目
     * @param id
     * @return ResponseResult
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询护理项目")
    public ResponseResult getById(@ApiParam("护理项目id") @PathVariable Long id) {
        NursingProjectVo nursingProjectVo = nursingProjectService.getById(id);
        return ResponseResult.success(nursingProjectVo);
    }

    /**
     *  更新护理项目
     * @param nursingProjectDto
     * @return
     */
    @PutMapping
    @ApiOperation(value = "更新护理项目")
    public ResponseResult update(@RequestBody NursingProjectDto nursingProjectDto) {
        nursingProjectService.update(nursingProjectDto);
        return ResponseResult.success();
    }

    /**
     * 删除护理项目
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除护理项目")
    public ResponseResult delete(@ApiParam("护理项目id") @PathVariable Long id) {
        nursingProjectService.delete(id);
        return ResponseResult.success();
    }

    /**
     *  查询所有护理项目
     * @return
     */
    @GetMapping("/all")
    @ApiOperation(value = "查询所有护理项目")
    public ResponseResult<List<NursingProjectVo>> getAll() {
        List<NursingProjectVo> all = nursingProjectService.getAll();
        return ResponseResult.success(all);
    }

    /**
     *  启用禁用护理项目
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "启用禁用护理项目")
    public ResponseResult enableOrDisable(@ApiParam("护理项目id") @PathVariable Long id,
                                          @ApiParam("状态") @PathVariable Integer status) {
        nursingProjectService.enableOrDisable(id, status);
        return ResponseResult.success();
    }
}
